package com.example.book.mapper;

import com.example.book.model.BookInfo;
import com.example.book.model.PageResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.awt.print.Book;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-12-10
 * Time: 20:28
 */
@Mapper
public interface BookMapper {
    @Insert("insert into book_info (book_name , author , count , price , " +
            "publish , status ) values (#{bookName} , #{author} , " +
            "#{count} , #{price} , #{publish} , #{status})")
    Integer insertBook(BookInfo bookInfo);

//    order by 写到where语句后面

    @Select("select * from book_info where status != 0 order by id desc limit #{offset},#{limit}")
    List<BookInfo> queryBookByPage(Integer offset , Integer limit);

    @Select("select count(1) from book_info where status != 0")
    Integer count();

//    把图书显示到页面上，（1：获取所有图书的信息）
    @Select("select * from book_info where id = #{bookId}")
    BookInfo queryBookById(Integer bookId);

//    因为参数过多我们采用XML的方式来写,这里的sql语句不支持返回String类型，会报异常
    Integer updateBook(BookInfo bookInfo);

    Integer batchDeleteBookByIds(List<Integer> ids);


}
